package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.minewar.MineStationInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class MineWarDaoImpl extends TempDao {

	public Map<Integer, Map<Integer, MineStationInfo>> getMineStationInfoMap() {
		Map<Integer, Map<Integer, MineStationInfo>> dataMap = new ConcurrentHashMap<>();
		ResultSet rs = null;
		CallableStatement call = null;
		String sql = "select * from t_p_mine order by id";
		try {
			getDb().setConnName(DbNameStrategy.getConfigDb());
			call = getDb().getConnection().prepareCall(sql);
			rs = call.executeQuery();
			while (rs.next()) {
				MineStationInfo data = new MineStationInfo();
				data.setMineType(rs.getInt("type"));
				data.setStationId(rs.getInt("id"));
				data.setPosition(rs.getInt("pos"));
				data.setStationName(rs.getString("name"));
				data.setPitCount(rs.getInt("capacity"));
				data.setOutputSpeedAddition(rs.getInt("outputSpeed"));
				data.setAddOutputSpeedAddition(rs.getInt("outSpeedAdd"));
				data.setShowAbility(rs.getBoolean("isShowPower"));
				data.setShowStationIndex(rs.getInt("descNum"));
				if(!dataMap.containsKey(data.getMineType())){
					dataMap.put(data.getMineType(), new ConcurrentHashMap<>());
				}
				dataMap.get(data.getMineType()).put(data.getStationId(), data);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			getDb().closeConnection(call, rs);
		}
		return dataMap;
	}

}
